//
// Created by 成飞 on 2024/1/3.
//

#ifndef ORDERKV_COMMAND_PARSER_HPP
#define ORDERKV_COMMAND_PARSER_HPP

#include <iostream>
#include <sstream>
#include <vector>
#include <string>

using namespace std;

class CommandParser{

public:
    void parse_input(const string& userInput) {
        istringstream iss(userInput);
        string command;
        iss >> command;

        vector<string> args;
        string arg;
        while(iss >> arg) args.push_back(arg);

        if (command == "put") {
            insert_parse(args);
        } else if (command == "update") {
            update_parse(args);
        } else if(command == "query"){
            query_parse(args);
        } else if(command == "delete") {
            delete_parse(args);
        } else if(command.empty()) {
            return;
        } else {
            cout << "Unknown command: " << command << endl;
            return;
        }
    }

private:
    void insert_parse(const vector<string> &args){
        if(args.size() > 2){
            args_nums_err_print();
            return;
        }
        const string& key = args[0];
        const string& val = args[1];
        cout << "put " << key << " " << val << endl;
    }

    void query_parse(const vector<string> &args){

    }

    void update_parse(const vector<string> &args){

    }

    void delete_parse(const vector<string> &args){

    }

    static void args_nums_err_print(){
        cout << "wrong arguments number!" << endl;
    }
};


#endif //ORDERKV_COMMAND_PARSER_HPP
